# -*- coding:utf-8 -*-
import time
from selenium.webdriver.support.ui import WebDriverWait
from Public_way.AutoTestLog import Logger

class RegisterDoctor():

    def __init__(self, driver):
        self.driver = driver



    def StartRegister(self, Phone, code, Pass):
        logger2 = Logger()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/et_psw')).click()
        # 点击注册按钮
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_name('注册')).click()
        logger2.log(u'医生端-医生点击注册按钮')
        # 输入手机号
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/et_phone')).send_keys(Phone)
        logger2.log(u'医生端-输入手机号')
        # 点击获取验证码
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_go_reg')).click()
        logger2.log(u'医生端-点击获取验证码')
        # 输入验证码
        self.Ucode(code)
        logger2.log(u'医生端-输入验证码')
        # 设置登录密码
        WebDriverWait(self.driver, 50).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/new_pwd')).send_keys(Pass)
        WebDriverWait(self.driver, 50).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/new_pwd_repeat')).send_keys(Pass)
        logger2.log(u'医生端-设置登录密码')
        # 回收键盘
        self.driver.tap([(979, 1126)], 50)
        time.sleep(3)
        WebDriverWait(self.driver, 50).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_go_reg')).click()
        logger2.log(u'医生端-准备医师认证')


    def DoctorData(self, D_Name, D_IdCard, Adept):
        logger2 = Logger()
        # 登录成功-准备进行医师认证
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/physician_info_ed_name')).send_keys(D_Name)
        logger2.log(u'医生端-姓名输入完成')
        # 身份证
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/physician_info_ed_cardid')).send_keys(D_IdCard)
        logger2.log(u'医生端-身份证输入完成')
        # 医院
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/physician_info_tv_hosp')).click()
        logger2.log(u'医生端-医院选中完成')
        time.sleep(5)
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_complete_search')).click()
        # 科室
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/physician_info_tv_keshi')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/item_tv_subname')).click()
        logger2.log(u'医生端-科室选择完成')
        # 擅长
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/choose_num')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/good_tag')).send_keys(Adept)
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/btn_add_tag')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/back_next')).click()
        logger2.log(u'医生端-擅长输入完成')
        # 职称
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/physician_info_tv_zhi')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/item_physican_qualificat_name')).click()
        logger2.log(u'医生端-职称选择完成')
        # 提交医师资料
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/physician_info_tv_next')).click()
        logger2.log(u'医生端-提交医师资料')

    def DoctorPhont(self):
        logger2 = Logger()
        # 上传医师头像
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/up_head_phone_img')).click()
        logger2.log(u'医生端-准备进行头像上传')
        # 拍照
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/takePhoto')).click()
        # oppo的组件名称都是oppo自带的
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.oppo.camera:id/shutter_button')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.oppo.camera:id/btn_done')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/clip')).click()
        logger2.log(u'医生端-拍照完成')
        # 点击下一步
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/uphead_assess_audit')).click()
        logger2.log(u'医生端-头像上传成功')

    def Certificate(self):
        logger2 = Logger()
        # 首页
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/eligiby_assess_upphoto')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/takePhoto')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.oppo.camera:id/shutter_button')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.oppo.camera:id/btn_done')).click()
        logger2.log(u'医生端-执业证书-首页照片上传成功')
        # 第二页
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/eligiby_assess_upphoto_book')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/takePhoto')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.oppo.camera:id/shutter_button')).click()
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.oppo.camera:id/btn_done')).click()
        logger2.log(u'医生端-执业证书-第二页照片上传成功')
        # 提交
        WebDriverWait(self.driver, 10).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/eligiby_assess_audit')).click()
        logger2.log(u'医生端-提交成功-等待审核-我在个人中心')
        state = WebDriverWait(self.driver, 30).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.doctor:id/tv_phyinfo')).text.encode('utf-8')
        logger2.log('医生端-我目前的状态为：[%s]' % state)

    def Ucode(self, code):
        logger2 = Logger()
        time.sleep(6)
        # 输入验证码
        for i in code:
            if i == '0':
                self.driver.tap([(537, 1847)], 500)
            elif i == '1':
                self.driver.tap([(186, 1362)], 500)
            elif i == '2':
                self.driver.tap([(537, 1362)], 500)
            elif i == '3':
                self.driver.tap([(903, 1362)], 500)
            elif i == '4':
                self.driver.tap([(182, 1515)], 500)
            elif i == '5':
                self.driver.tap([(541, 1515)], 500)
            elif i == '6':
                self.driver.tap([(897, 1515)], 500)
            elif i == '7':
                self.driver.tap([(180, 1676)], 500)
            elif i == '8':
                self.driver.tap([(549, 1676)], 500)
            elif i == '9':
                self.driver.tap([(906, 1676)], 500)
        logger2.log(u'医生端-验证码输入完成')
